﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TSharp.Core.Mvc;
using TSharp.Core.Util;
using TSharp.Core.Appbox.Models;
using System.Configuration;
using System.Xml;

namespace TSharp.Core.Appbox.Controllers
{
    public class HomeController : Controller
    {
        class a : TSharp.Core.Appbox.Models.IPositionRM
        {
            public string RMPositionNK { get; set; }
            public string RM { get; set; }
            public string RMPositionEployeeName { get; set; }
            public int Year { get; set; }
            public int Month { get; set; }
            public string GetPeriod()
            {
                return "";
            }

            public DateTime BuidDate { get; set; }
            public string SUPositionNK { get; set; }
            public string SU { get; set; }
            public string SUPositionEployeeName { get; set; }
            public string BU { get; set; }
        }
        [ValidateMvcCaptchaAttribute("abc")]
        public ActionResult Index()
        {

            if (ModelState.IsValid)
            {
                ViewBag.Message = "Validate Ok! Welcome to ASP.NET MVC!";
            }
            else
            {
                ViewBag.Message = "Validate Fail! Welcome to ASP.NET MVC!";

            }
            List<PathInfo> list = new List<PathInfo>();
            var values = Enum.GetNames(typeof(System.Environment.SpecialFolder));
            foreach (string v in values)
            {
                list.Add(new PathInfo
                {
                    Enum = v,
                    Path = System.Environment.GetFolderPath(v.ToEnum<string, System.Environment.SpecialFolder>())
                });
            }



            return View(list);
        }

        public ActionResult About()
        {
            return View(new a());
        }
        [HttpGet]
        public ActionResult Setting()
        {
            var model = new SettingViewModel();
            var con = ConfigurationManager.ConnectionStrings["EFConnection1"];
            if (con != null)
                model.ConnectionString = con.ConnectionString;
            return View(model);
        }
        [HttpPost]
        public ActionResult Setting(SettingViewModel model)
        {
            if (ModelState.IsValid)
            {
                var cfg =
                    ConfigurationHepler.GetConfigConfiguration(
                        AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                if (cfg.ConnectionStrings.ConnectionStrings["EFConnection1"] == null)
                    cfg.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("EFConnection1",
                        ""));
                cfg.ConnectionStrings.ConnectionStrings["EFConnection1"].ConnectionString = model.ConnectionString;

                cfg.Save();
            }
            return View(model);
        }

    }
}
